home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #005 (19xx)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #005 (19xx)(Amiga User Group Deutschland e.V.).adf / RainBow / rainbow.c < prev    next >
C/C++ Source or Header  |  1986-10-22  |  4KB  |  111 lines

  1. /* rainbow.c : Marauder-style rainbow generator - (c) 1987 DJH
  2.  
  3.     As some would put it, this program is a "parlour trick" very
  4.   similar to that used in the Marauder II disk copier. Quite a simple
  5.   concept, actually; install a user copper list such that the background
  6.   color (hardware color 0) is changed every few scan lines. I was even able
  7.   to change the background color every WORD during testing! Try filling the
  8.   screen with WorkBench color 1 and rendering text in color 0 for a Genlock-
  9.   style effect; the rainbow shows through the letters themselves!
  10.  
  11.   P.S. This program compiled under Manx 3.4; no need to declare RKM includes
  12.   if you condense them all into one big precompiled symbol table!
  13.  
  14.   P.P.S. Sorry for the lack of comments; but then again, this program was
  15.   a fast hack. Should be highly readable anyway.
  16. */
  17.  
  18. void *IntuitionBase,*GfxBase;
  19.  
  20. #define NUMCOLORS 66
  21.  
  22. UWORD colors[NUMCOLORS] = {
  23.   0xce3,0xae3,0x8e3,0x7e3,0x5e3,0x4e3,0x3e4,0x3e5,0x3e7,0x3e8,
  24.   0x3ea,0x3eb,0x3ec,0x3ee,0x3de,0x3ce,0x3ae,0x39e,0x37e,0x34e,
  25.   0x33e,0x43e,0x63e,0x73e,0x83e,0xa3e,0xb3e,0xc3e,0xe3e,0xe3d,
  26.   0xe3b,0xe3a,0xe39,0xe37,0xe36,0xe34,0xe33,0xe53,0xe63,0xe83,
  27.   0xe93,0xea3,0xeb3,0xec3,0xee3,0xde3,0xbe3,0x8e3,0x7e3,0x4e3,
  28.   0x3e4,0x3e5,0x3e6,0x3e8,0x3e9,0x3ea,0x3ec,0x3ed,0x3ee,0x3de,
  29.   0x3be,0x3ae,0x38e,0x37e,0x36e,0x34e
  30. };
  31.  
  32. main(argc,argv)
  33. int argc;
  34. char *argv[];
  35. {
  36.   struct Window *window;
  37.   struct ViewPort *vp;
  38.   struct UCopList *ucop;
  39.  
  40.   void *dspins,*sprins,*clrins; /* intermediate Copper cache ptrs */
  41.  
  42.   struct NewWindow nw;
  43.   UWORD bgpen=0,i,j=1;
  44.  
  45.   if (argc==2) bgpen=*argv[1]-'0';
  46.   if (bgpen>3) { puts("Usage : rainbow [default color (0-3)]"); exit(0); }
  47.        
  48.   GfxBase=OpenLibrary("graphics.library",0);
  49.   IntuitionBase=OpenLibrary("intuition.library",0);
  50.  
  51.   setmem(&nw,sizeof(nw),0);
  52.  
  53.   nw.Height=50; nw.Width=316;
  54.   nw.DetailPen=nw.BlockPen=-1;
  55.   nw.Flags=WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH;
  56.   nw.IDCMPFlags=CLOSEWINDOW;
  57.   nw.Title=(UBYTE *)"Rainbow (c) 1987 John Hodgson";
  58.   nw.Type=WBENCHSCREEN; /* 'cuz we want the WB Screen ptr */
  59.  
  60.   window=OpenWindow(&nw);
  61.   vp=ViewPortAddress(window);
  62.  
  63.   /* look into CINIT for 1.2 or later */
  64.  
  65.   while (!GetMsg(window->UserPort)) {
  66.  
  67.   /* the goal is to assemble all the Copper lists and THEN update the
  68.      ViewPort pointer so Intuition won't see any partially constructed
  69.      lists. Note use of double-buffering; we don't want funny effects
  70.      if user tries to drag the screen around! */
  71.  
  72.     ucop=AllocMem(sizeof(struct UCopList),MEMF_CHIP|MEMF_CLEAR);
  73.  
  74.     for (i=0;i<NUMCOLORS;i++) {
  75.       CWAIT(ucop,i*(200/NUMCOLORS),0);
  76.       CMOVE(ucop,custom.color[bgpen],colors[(i+j) % NUMCOLORS]);
  77.     }
  78.     CEND(ucop); j++;
  79.  
  80.     /* Since the Copper lists are dynamically created, we'll need to free
  81.        'em up before creating new ones. It would be wasteful to free ALL
  82.        the ViewPort lists, since we'll only have to remake 'em later. By
  83.        limiting processing to the UCopList only, we can avoid a time-
  84.        consuming MakeScreen() operation. */
  85.  
  86.     /* cache all the Copper lists we want kept */
  87.     dspins=vp->DspIns; sprins=vp->SprIns; clrins=vp->ClrIns;
  88.  
  89.     Forbid(); /* don't let Intuition see our cleanup */
  90.  
  91.     vp->DspIns=vp->SprIns=vp->ClrIns=0; /* hide these from FVPCL() */
  92.     FreeVPortCopLists(vp); /* free UCopIns from previous pass */
  93.  
  94.     /* cleanup done, uncover "hidden" copper lists */
  95.     vp->DspIns=dspins; vp->SprIns=sprins; vp->ClrIns=clrins;
  96.  
  97.     vp->UCopIns=ucop; /* install new UCopIns */
  98.  
  99.     Permit();
  100.     RethinkDisplay();
  101.   }
  102.  
  103.   /* No need to optimize for cleanup; free ALL lists & recreate 'em */
  104.  
  105.   FreeVPortCopLists(vp); RemakeDisplay();
  106.  
  107.   CloseWindow(window);
  108.   CloseLibrary(IntuitionBase);
  109.   CloseLibrary(GfxBase);
  110. }
  111.